from django.db import models

# Create your models here.
'''
商品分类表
    商品名称
    商品图片
'''
class Cate(models.Model):
    cate_name = models.CharField(max_length=32,verbose_name='分类名称')
    cate_img = models.ImageField(upload_to='cate_img',verbose_name='分类图片')
    class Meta:
        db_table = 'cate'
        verbose_name = '商品分类'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.cate_name



'''
轮播图的批号：
    第一批：

轮播图的图片：
    批号：外键
    图片：
'''
class Carousel(models.Model):
    '''
    轮播图批号
    '''
    carousel = models.CharField(max_length=20)
    class Meta:
        db_table = 'carouserl'
    def __str__(self):
        return self.carousel


class Picture(models.Model):
    '''
    轮播图的图片
    '''
    carousel = models.ForeignKey(Carousel,on_delete=models.CASCADE)
    prcture = models.ImageField(upload_to='picture')
    class Meta:
        db_table = 'picture'

    def __str__(self):
        return str(self.id)


class Goods(models.Model):
    """
    商品表：
        商品名称，图片，价格，单位，简介，详情，分类（外键）
    """
    goods_name = models.CharField(max_length=32)
    goods_img = models.ImageField(upload_to='goods')
    goods_price = models.DecimalField(max_digits=8,decimal_places=2)
    goods_unit = models.CharField(max_length=8)
    goods_describe = models.CharField(max_length=500)
    goods_content = models.CharField(max_length=500)
    cate = models.ForeignKey(Cate,on_delete=models.CASCADE)

    class Meta:
        db_table = 'goods'

    def __str__(self):
        return self.goods_name


class User(models.Model):
    username = models.CharField(max_length=32)
    password = models.CharField(max_length=128)
    email = models.EmailField()
    status = models.BooleanField(default=0)

    class Meta:
        db_table = 'user'

    def __str__(self):
        return self.username


class UserToken(models.Model):
    user = models.OneToOneField(User,on_delete=models.CASCADE)
    token = models.CharField(max_length=200)

    class Meta:
        db_table = 'user_token'

    def __str__(self):
        return self.token



